/**
 * 图像标签检测服务aksk请求方式的使用示例
 */
const { json } = require("body-parser");
var tagging = require("./image_sdk/image_tagging");
var utils = require("./image_sdk/utils");

// 初始化服务的区域信息，目前支持华北-北京(cn-north-4)、亚太-香港(ap-southeast-1)等区域信息
utils.initRegion("cn-north-4");

var app_key = "2A33VMC62WMLWFDBQDNC";
var app_secret = "zyaRSs2WjtF0oxsnzwBKQp8RENyTv2TEOWQvRaTY";

class TaggingTool {
    constructor(obj) {
        for (let key in obj) {
            this[key] = obj[key];
        }
        this.data_url = "https://copy-right-content.obs.cn-north-4.myhuaweicloud.com/" + this.image_name;
    }

    tag(cb) {
        var data = utils.changeFileToBase64(this.filepath);
        tagging.image_tagging_aksk(
            app_key,
            app_secret,
            data,
            this.data_url,
            60,
            "en",
            3,
            function (result) {
                var res = JSON.parse(result)
                var ret = {
                    tag1: typeof (res['result']['tags'][0]) === 'undefined' ?
                        None : res['result']['tags'][0]['tag'],
                    tag2: typeof (res['result']['tags'][1]) === 'undefined' ?
                        None : res['result']['tags'][1]['tag'],
                    tag3: typeof (res['result']['tags'][2]) === 'undefined' ?
                        None : res['result']['tags'][2]['tag'],
                }
                console.log(ret);
                cb(ret);
            }
        );
    }
}

module.exports = TaggingTool;


